package dao

import (
	"errors"
	"go-zero-example/cmd/userrpc/internal/model"
	"go-zero-example/cmd/userrpc/internal/util"
)

type (
	UserDao struct {
	}
)

// Register 插入用户
func (u *UserDao) Register(user *model.User) error {
	orm := util.Orm
	_, err := orm.InsertOne(user)

	return err
}

// GetUserByUid 返回用户通过id
func (u *UserDao) GetUserByUid(user *model.User) error {
	orm := util.Orm
	_, err := orm.Get(user)
	return err
}

// RePhoneByUid 修改用户手机号通过id
func (u *UserDao) RePhoneByUid(user *model.User) error {
	orm := util.Orm
	affect, err := orm.Where("id = ?", user.Id).Update(user)
	if err != nil {
		return err
	} else if affect == 0 {
		return errors.New("")
	}
	return err
}
